<template>
<div class="c-add">
<edit-cust
:isMerge="false"
:isBlight="false"
:labelValue="3"
:currentBusinessObj="currentBusinessObj"
@addCustomer="addCust"
>
</edit-cust>
</div>
</template>
<script>
  import editCust from './AddCustomer.vue'
  import {deepClone} from '@/utils/m7Utils.js'
  export default {
    name: 'AddCustomers',
    data () {
      return {
        currentBusinessObj: {
          type: 'customer',
          tabType: 'customer_my',
          labelValue: 3
        }
      }
    },
    components: {
      editCust
    },
//    beforeRouteLeave (to, from, next) {
//      this.$destroy()
//      next()
//    },
    methods: {
      addCust (form) {
        let cur = deepClone(form)
        this.$store.dispatch('addCustomer', form).then((val) => {
          // 自定义操作
          let currentCustomer = val.data
          let _id = currentCustomer._id
          if (_id) {
            // 知道添加的客户跳到哪个添加的模块  我的客户 或者 全部
            this.$router.push(`/index/customer/?addSuccess=${cur.tabType}`)
          } else {
            this.$message.error(this.$t('customer.addCustomerFailed'))
          }
        })
      }
    }
  }
</script>
